
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <!--<div class="layui-card-header">修改密码</div>-->
                <div class="layui-card-body" pad15>
                    <div class="layui-form" lay-filter="user-set-password-form" id="user-set-password-form" style="padding: 20px 30px 0 0;">
						<form id="user-set-password-form-form">
	                        <div class="layui-form-item">
	                            <label class="layui-form-label">旧密码</label>
	                            <div class="layui-input-block">
	                                <input type="password" name="oldPassword"  placeholder="" autocomplete="off" class="layui-input required">
	                            </div>
	                        </div>
	                        <div class="layui-form-item">
	                            <label class="layui-form-label">新密码</label>
	                            <div class="layui-input-block">
	                                <input type="password" id="newPassword" name="newPassword" minlength="8" class="layui-input required">
	                            </div>
	                        </div>
	                        <div class="layui-form-item">
	                            <label class="layui-form-label">确认新密码</label>
	                            <div class="layui-input-block">
	                                <input type="password" name="checkPassword" class="layui-input required">
	                            </div>
	                        </div>
	                        <!--<div class="layui-form-item">
	                            <div class="layui-input-block">
	                                <button class="layui-btn layui-btn-default" lay-submit lay-filter="user-set-password-form-submit">确认修改</button>
	                            </div>
	                        </div>-->
                        </form>
                        <div class="layui-form-item">
                            <label class="layui-form-label"></label>
                            <div class="layui-input-inline">
                                <input id="user-set-password-form-submit" type="button" lay-submit lay-filter="user-set-password-form-submit" value="确认" class="layui-btn layui-btn-default">
                            </div>
                        </div>
                    </div>
                    </div>
                </div>
        </div>
    </div>
</div>
<script>
	$.validator.addMethod("newPassword", function(value, elements){
		var reg1 = /[a-z]+/g;
		var reg2 = /[A-Z]+/g;
		var reg3 = /[0-9]+/g;
		var reg4 = /[`\\~!@#$%^*()_+?:{},.\/;[\]|]/g;
		var count = 0;
		if(reg1.test(value)){
			count++;
		}
		if(reg2.test(value)){
			count++;
		}
		if(reg3.test(value)){
			count++;
		}
		if(reg4.test(value)){
			count++;
		}
		if(count<3){
			return false;
		}else{
			return true;
		}
    }, "密码必须包含字母大写、字母小写、数字、特殊符号任意三种及以上");
	
	
    layui.use(['common', 'view'], function () {
        var $ = layui.$
            , R = layui.common
            , view = layui.view;
            
        R.setFormLang('user-set-password-form');
            
        $("#user-set-password-form-submit").on("click",function(){
        	var validateForm = $("#user-set-password-form-form").validate({
        		rules: {  
					newPassword:{    
			            newPassword:true,  
			        }   
				}
        	});
			
        	if(validateForm.form()){
				var data = myHelper.composeData($("#user-set-password-form-form"));
				
				if (data.newPassword == data.oldPassword){
					 return view.warn(layui.admin.lang() ? 'The new password is the same as the old one. Please change it.' : '新密码与旧密码相同，请修改。'), false;
				}
                else if (data.newPassword != data.checkPassword){
                	  return view.warn(layui.admin.lang() ? 'The two passwords are inconsistent.' : '两次密码不一致。'), false;
                }else{
//					data.oldPassword = encryptByDES(data.oldPassword,"abcdefgabcdefg12");
//					data.newPassword = encryptByDES(data.newPassword,"abcdefgabcdefg12");
                	LayerUtil.ajax({
						shade: true,
						type: 'post',
			    		url: layui.admin.basePath + '/sys/user/changePassword?oldPassword=' + data.oldPassword + '&newPassword=' + data.newPassword,
			    		success: function(result){
			    			LayerUtil.success(result[LayerUtil.getMsgLang()]);
			    		}
			  		});
                }
        	}
	            	
        })
            
        function encryptByDES(message, key) {
            var keyHex = CryptoJS.enc.Utf8.parse(key);
            var encrypted = CryptoJS.AES.encrypt(message, keyHex, {
                mode: CryptoJS.mode.ECB,
                padding: CryptoJS.pad.Pkcs7
            });
            return encrypted.toString();
        }
        
        /*R.initForm({
            formLay: 'user-set-password-form'
            , subUrl:  layui.admin.basePath + '/Admin/updateUserPassword'
            , verify: function (data) {
                if (data.newPassword == data.oldPassword)
                    return view.warn(layui.admin.lang() ? 'The new password is the same as the old one. Please change it.' : '新密码与旧密码相同，请修改。'), false;


                if (data.newPassword != data.checkPassword)
                    return view.warn(layui.admin.lang() ? 'The two passwords are inconsistent.' : '两次密码不一致。'), false;
                
            }
        })*/
    })
</script>